/*     */ package btsm.servlet;
/*     */ 
/*     */ import java.io.IOException;
import java.util.Date;
import java.util.List;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;

import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;

import btsm.bean.sqlUsersWork;

import com.yc.dao.SystemDAO;
import com.yc.dao.model.SysmMenuBO;
import com.zhonglee.filter.OnlineSession;
import com.zhonglee.filter.SessionListener;
import com.zhonglee.util.SerialCodeSample;

/*     */ public class check_user extends HttpServlet
/*     */ {	
				private Log log = LogFactory.getLog(getClass());
/*     */   private SystemDAO systemDAO;
/*  30 */   private static String admin = "admin";
/*     */ 
/*     */   public void init()
/*     */     throws ServletException
/*     */   {
/*  35 */     this.systemDAO = new SystemDAO();
/*     */   }
/*     */ 
/*     */   public void doGet(HttpServletRequest request, HttpServletResponse response)
/*     */     throws ServletException, IOException
/*     */   {
/*  41 */     String strSeraction = request.getParameter("seraction");
/*     */ 
/*  43 */     if (strSeraction == null) {
/*  44 */       strSeraction = "";
/*     */     }
/*  46 */     if (strSeraction.equalsIgnoreCase("serlogin")) {
/*  47 */       sqlUsersWork PC = new sqlUsersWork("users", "0");
/*  48 */       response.setContentType("text/html;charset=UTF8");
/*  49 */       HttpSession session = request.getSession();
/*  50 */       String strUsername = request.getParameter("UserName");
/*  51 */       String password = request.getParameter("password");
/*  52 */       String strRand = request.getParameter("rand");
/*  53 */       String msg = ""; String strRedURL = "";
/*     */ 
					log.info("strUsername "+ strUsername);
					log.info("password "+ password);
					log.info("strRand "+ strRand);
/*  55 */       if ((strRand == null) || ("".equalsIgnoreCase(strRand.trim())))
/*     */       {
					
/*  57 */         request.getSession().setAttribute("LOGIN_ERROR_MSG", "请输入随机码！");
/*  58 */         response.sendRedirect("login.jsp");
/*  59 */        log.warn("Rand code is null, please input it again.'");
					return;
/*     */       }
/*     */ 
/*  62 */       if (!strRand.equalsIgnoreCase(request.getSession().getAttribute("rand").toString()))
/*     */       {
/*  64 */         request.getSession().setAttribute("LOGIN_ERROR_MSG", "输入的随机码不正确！");
/*  65 */         response.sendRedirect("login.jsp");
					 log.warn("Rand code is not correct and input it again.");	
/*  66 */         return;
/*     */       }
/*  68 */       request.getSession().removeAttribute("rand");
/*     */ 
/*  72 */       boolean result = PC.checkLogin(strUsername, password);
/*  73 */       log.info("Check is value is ["+result+"]");
					if (result)
/*     */       {
///*  75 */         if (admin.equals(strUsername))
///*     */         {
///*  77 */           session.setAttribute("stxtUName", strUsername);
///*  78 */           response.sendRedirect("serialcode.jsp");
///*  79 */           log.info("strUsername = " + strUsername);
///*  80 */           return;
///*     */         }
/*     */ 
					boolean machineCode = SerialCodeSample.getRegStatus();
					machineCode = true;
/*  83 */         if (machineCode) {
/*  84 */           session.setAttribute("login", "1");
/*  85 */           session.setAttribute("stxtUName", strUsername);
/*  86 */           session.setAttribute("IS_LOGIN", Boolean.TRUE);
/*  87 */           session.setAttribute("_login", new OnlineSession(request.getRemoteAddr(), strUsername, new Date().toString()));
/*     */ 
/*  89 */           log.info("用户:" + strUsername + " 登入系统，IP地址：" + request.getRemoteAddr() + " 时间：" + new Date().toString());
/*     */ 
/*  96 */           strRedURL = "/btsm/pages/load.jsp";
/*     */ 
/*  98 */           List menuList = this.systemDAO.getAllMenuByUserID(strUsername, "0");
/*  99 */           if (menuList != null)
/*     */           {
/* 101 */             int menuCount = menuList.size();
/* 102 */             for (int i = 0; i < menuCount; i++)
/*     */             {
/* 104 */               SysmMenuBO bo = (SysmMenuBO)menuList.get(i);
/* 105 */               if (("true".equalsIgnoreCase(bo.getLEAF_FLAG())) && (!"0".equalsIgnoreCase(bo.getPARENT_ID())))
/*     */               {
/* 107 */                 String strFirstPage = bo.getLINK();
/* 108 */                 session.setAttribute("FIRST_PAGE", strFirstPage);
/* 109 */                 break;
/*     */               }
/*     */             }
/*     */           }
/* 113 */           String strUserRole = this.systemDAO.getRoleNameByUserName(strUsername);
/* 114 */           request.getSession().setAttribute("USER_ROLE", strUserRole);
/* 115 */           request.getSession().removeAttribute("LOGIN_ERROR_MSG");
/*     */         } else {
/* 117 */           msg = "尚未注册或者注册码已过期！";
/* 118 */           strRedURL = "login.jsp";
/* 119 */           request.getSession().setAttribute("LOGIN_ERROR_MSG", msg);
/*     */         }
/*     */ 
/*     */       }
/*     */       else
/*     */       {
/* 128 */         msg = "输入的用户名或者密码错误！";
/* 129 */         strRedURL = "login.jsp";
/* 130 */         request.getSession().setAttribute("LOGIN_ERROR_MSG", msg);
/*     */       }
/*     */ 
/* 133 */       PC.dbConClose();
/*     */ 
/* 135 */       request.setAttribute("msg", msg);
/*     */ 
/* 137 */       response.sendRedirect(strRedURL);
/* 138 */     } else if (strSeraction.equalsIgnoreCase("seronlUN"))
/*     */     {
/* 140 */       StringBuffer results = new StringBuffer("<properties>");
/* 141 */       String strOnlUN = String.valueOf(SessionListener.getSize());
/*     */ 
/* 144 */       results.append("<property>");
/* 145 */       results.append("<onlineun>");
/* 146 */       results.append(strOnlUN);
/* 147 */       results.append("</onlineun>");
/* 148 */       results.append("</property>");
/*     */ 
/* 150 */       results.append("</properties>");
/* 151 */       response.setContentType("text/xml;charset=UTF-8");
/*     */ 
/* 153 */       response.getWriter().write(results.toString());
/* 154 */     } else if (strSeraction.equalsIgnoreCase("serlogout")) {
/* 155 */       HttpSession sessionT = request.getSession();
/* 156 */       String strUsername = (String)sessionT.getAttribute("stxtUName");
/* 157 */       sessionT.invalidate();
/* 158 */       log.info("用户" + strUsername + "退出！" + new Date().toString());
/*     */     }
/*     */   }
/*     */ 
/*     */   public void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException
/*     */   {
/* 164 */     doGet(request, response);
/*     */   }
/*     */ 
/*     */   public void destroy()
/*     */   {
/*     */   }
/*     */ }

/* Location:           E:\java\apache-tomcat-6.0.36\webapps\btsm\WEB-INF\classes\
 * Qualified Name:     btsm.servlet.check_user
 * JD-Core Version:    0.6.2
 */